/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * OrderEdit.java
 *
 * Created on 2009-12-6, 20:20:24
 */
package com.ordering.menu;

import com.ordering.dao.TMenuJpaController;
import com.ordering.dao.TOrderDetailJpaController;
import com.ordering.dao.TOrderHeadJpaController;
import com.ordering.dao.VipCustomerJpaController;
import com.ordering.dao.exceptions.IllegalOrphanException;
import com.ordering.dao.exceptions.NonexistentEntityException;
import com.ordering.pojo.TMenu;
import com.ordering.pojo.TOrderDetail;
import com.ordering.pojo.TOrderHead;
import com.ordering.pojo.UserManage;
import com.ordering.pojo.VipCustomer;
import com.ordering.utils.WindowLocationUtils;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author hua
 */
public class OrderEdit extends javax.swing.JDialog {

    /** Creates new form OrderEdit */
//    public OrderEdit(java.awt.Frame parent, boolean modal) {
//        super(parent, modal);
//        initComponents();
//    }
    private String operatStatus = "ADDNEW";

    public String getOperatStatus() {
        return operatStatus;
    }
    private UserManage user;

    public UserManage getUser() {
        return user;
    }

    public void setUser(UserManage user) {
        this.user = user;
    }

    public void setOperatStatus(String operatStatus) {
        this.operatStatus = operatStatus;
    }

    public OrderEdit() {
        this(null, null);
    }

    public OrderEdit(TOrderHead orderHead, String operatStatus) {
        this.tOrderHead1 = orderHead;
        this.operatStatus = operatStatus;
        initComponents();
        if ("EDIT".equalsIgnoreCase(operatStatus)) {
            actAmount.setEnabled(true);
        }
        this.setEnabled(true);
        WindowLocationUtils.setWindowCenter(this);
        initTable();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        if(tOrderHead1==null)
        tOrderHead1 = new com.ordering.pojo.TOrderHead();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        orderStatus = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jTextField6 = new javax.swing.JTextField();
        jTextField7 = new javax.swing.JTextField();
        amount = new javax.swing.JTextField();
        actAmount = new javax.swing.JTextField();
        jTextField10 = new javax.swing.JTextField();
        createDate = new javax.swing.JTextField();
        jTextField12 = new javax.swing.JTextField();
        updateTime = new javax.swing.JTextField();
        jScrollPane6 = new javax.swing.JScrollPane();
        orderDetailTable = new javax.swing.JTable();
        jMenuBar1 = new javax.swing.JMenuBar();
        btnFinished = new javax.swing.JMenu();
        btnViewVIP = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("订单编辑");
        setAlwaysOnTop(true);

        jLabel1.setText("订单号");
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText("会员卡号");
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText("订单状态");
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText("订单类型");
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setText("桌号");
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText("电话号码");
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setText("送餐地址");
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setText("实收");
        jLabel8.setName("jLabel8"); // NOI18N

        jLabel9.setText("应收");
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel10.setText("下单人");
        jLabel10.setName("jLabel10"); // NOI18N

        jLabel11.setText("下单时间");
        jLabel11.setName("jLabel11"); // NOI18N

        jLabel12.setText("结算人");
        jLabel12.setName("jLabel12"); // NOI18N

        jLabel13.setText("结算时间");
        jLabel13.setName("jLabel13"); // NOI18N

        jTextField1.setEnabled(false);
        jTextField1.setName("jTextField1"); // NOI18N

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tOrderHead1, org.jdesktop.beansbinding.ELProperty.create("${orderNo}"), jTextField1, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        jTextField2.setEnabled(false);
        jTextField2.setName("jTextField2"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tOrderHead1, org.jdesktop.beansbinding.ELProperty.create("${orderType}"), jTextField2, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        orderStatus.setEnabled(false);
        orderStatus.setName("orderStatus"); // NOI18N
        orderStatus.setText("100".equalsIgnoreCase(tOrderHead1.getOrderStatus())?"未结算":"已结算");

        jTextField4.setEnabled(false);
        jTextField4.setName("jTextField4"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tOrderHead1, org.jdesktop.beansbinding.ELProperty.create("${cardNum}"), jTextField4, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        jTextField5.setEnabled(false);
        jTextField5.setName("jTextField5"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tOrderHead1, org.jdesktop.beansbinding.ELProperty.create("${tableNo}"), jTextField5, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        jTextField6.setEnabled(false);
        jTextField6.setName("jTextField6"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tOrderHead1, org.jdesktop.beansbinding.ELProperty.create("${phone}"), jTextField6, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        jTextField7.setEnabled(false);
        jTextField7.setName("jTextField7"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tOrderHead1, org.jdesktop.beansbinding.ELProperty.create("${address}"), jTextField7, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        amount.setEnabled(false);
        amount.setName("amount"); // NOI18N

        actAmount.setEnabled(false);
        actAmount.setName("actAmount"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tOrderHead1, org.jdesktop.beansbinding.ELProperty.create("${actualPrice}"), actAmount, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        jTextField10.setEnabled(false);
        jTextField10.setName("jTextField10"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tOrderHead1, org.jdesktop.beansbinding.ELProperty.create("${creatUser}"), jTextField10, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        createDate.setEnabled(false);
        createDate.setName("createDate"); // NOI18N
        if(tOrderHead1!=null&&tOrderHead1.getCreateDate()!=null)
        createDate.setText(tOrderHead1.getCreateDate().toString());

        jTextField12.setEnabled(false);
        jTextField12.setName("jTextField12"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tOrderHead1, org.jdesktop.beansbinding.ELProperty.create("${updateUser}"), jTextField12, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        updateTime.setEnabled(false);
        updateTime.setName("updateTime"); // NOI18N
        if(tOrderHead1!=null&&tOrderHead1.getUpdateDate()!=null)
        updateTime.setText(tOrderHead1.getUpdateDate().toString());

        jScrollPane6.setName("jScrollPane6"); // NOI18N

        orderDetailTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "菜  名", "种  类", "单  价", "数  量", "描  述"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Float.class, java.lang.Float.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, true, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        orderDetailTable.setEnabled(false);
        orderDetailTable.setMaximumSize(new java.awt.Dimension(2147483647, 200));
        orderDetailTable.setMinimumSize(new java.awt.Dimension(375, 200));
        orderDetailTable.setName("orderDetailTable"); // NOI18N
        orderDetailTable.setPreferredSize(new java.awt.Dimension(375, 200));
        jScrollPane6.setViewportView(orderDetailTable);

        jMenuBar1.setName("jMenuBar1"); // NOI18N

        btnFinished.setText("结算");
        btnFinished.setName("btnFinished"); // NOI18N
        btnFinished.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnFinishedMouseClicked(evt);
            }
        });
        jMenuBar1.add(btnFinished);

        btnViewVIP.setText("查看会员信息");
        btnViewVIP.setName("btnViewVIP"); // NOI18N
        btnViewVIP.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnViewVIPMouseClicked(evt);
            }
        });
        jMenuBar1.add(btnViewVIP);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 735, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(amount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(35, 35, 35)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel8))
                                .addGap(10, 10, 10)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(27, 27, 27)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(jLabel6)
                                                .addGap(18, 18, 18)
                                                .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(jLabel3)
                                                .addGap(18, 18, 18)
                                                .addComponent(orderStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                    .addComponent(actAmount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jTextField7)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextField12, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(35, 35, 35)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel11)
                            .addComponent(jLabel13))
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(createDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(updateTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {actAmount, amount, createDate, jTextField1, jTextField10, jTextField12, jTextField2, jTextField4, jTextField5, jTextField6, orderStatus, updateTime});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel10, jLabel11, jLabel12, jLabel13, jLabel2, jLabel3, jLabel4, jLabel5, jLabel6, jLabel7, jLabel8, jLabel9});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTextField2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(orderStatus, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTextField4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTextField5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTextField6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTextField7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(amount, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(actAmount, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTextField10, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(createDate, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTextField12, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(updateTime, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE)
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jLabel1, jLabel10, jLabel11, jLabel12, jLabel13, jLabel2, jLabel3, jLabel4, jLabel5, jLabel6, jLabel7, jLabel8, jLabel9});

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {actAmount, amount, createDate, jTextField1, jTextField10, jTextField12, jTextField2, jTextField4, jTextField5, jTextField6, jTextField7, orderStatus, updateTime});

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnFinishedMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnFinishedMouseClicked
        TOrderHeadJpaController control = new TOrderHeadJpaController();
        if (tOrderHead1.getId() != null) {
            try {
                if (user != null) {
                    tOrderHead1.setOrderStatus("200");
                    tOrderHead1.setUpdateUser(user.getUserid());
                    tOrderHead1.setUpdateDate(new Date());
                }
                control.edit(tOrderHead1);
            } catch (IllegalOrphanException ex) {
                Logger.getLogger(OrderEdit.class.getName()).log(Level.SEVERE, null, ex);
            } catch (NonexistentEntityException ex) {
                Logger.getLogger(OrderEdit.class.getName()).log(Level.SEVERE, null, ex);
            } catch (Exception ex) {
                Logger.getLogger(OrderEdit.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            control.create(tOrderHead1);
        }
        JOptionPane.showMessageDialog(this, "结算成功！");
        this.dispose();
    }//GEN-LAST:event_btnFinishedMouseClicked

    private void btnViewVIPMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnViewVIPMouseClicked
        if (tOrderHead1.getCardNum() == null || tOrderHead1.getCardNum().isEmpty()) {
            JOptionPane.showMessageDialog(this, "订单没有使用会员卡");
            return;
        }
        String sql = "select object(o) from VipCustomer as o where o.cardNum='" + tOrderHead1.getCardNum() + "'";
        VipCustomerJpaController control = new VipCustomerJpaController();
        List<VipCustomer> vips = control.findVipCustomerEntitiesBySQL(sql);
        if (vips != null && vips.size() > 0) {
            VipManageEdit win = new VipManageEdit(vips.get(0), "VIEW");
            win.setVisible(true);
        } else {
            JOptionPane.showMessageDialog(this, "没有找到对应的会员信息，请和管理员联系！");
            return;
        }
    }//GEN-LAST:event_btnViewVIPMouseClicked
    public void initTable() {
        for (int rowIndex = orderDetailTable.getRowCount() - 1; rowIndex > -1; rowIndex--) {
            ((DefaultTableModel) orderDetailTable.getModel()).removeRow(rowIndex);
        }
        String sql = "select object(o) from TOrderDetail as o where o.orderHeadId.id='" + tOrderHead1.getId() + "'";
        TOrderDetailJpaController detailControl = new TOrderDetailJpaController();
        List<TOrderDetail> cols = detailControl.findTOrderDetailEntitiesBySQL(sql);
        tOrderHead1.setTOrderDetailCollection(cols);
        Object[] rowData = new Object[orderDetailTable.getColumnCount()];
        TMenuJpaController control = new TMenuJpaController();
        Float orderAmount = new Float(0);
        for (TOrderDetail detail : cols) {
            TMenu menu = control.findTMenu(detail.getMenuId());
            if (menu != null) {
                rowData[0] = menu.getFoodName();
                rowData[1] = menu.getFoodTypeOid().getFoodTypeName();
                rowData[2] = menu.getPrice();
                rowData[3] = detail.getQty();
                rowData[4] = menu.getDescription();
                if (detail.getQty() != null && menu.getPrice() != null) {
                    orderAmount = orderAmount + detail.getQty() * menu.getPrice();
                }
                ((DefaultTableModel) orderDetailTable.getModel()).addRow(rowData);
            }
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                OrderEdit dialog = new OrderEdit();
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosed(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField actAmount;
    private javax.swing.JTextField amount;
    private javax.swing.JMenu btnFinished;
    private javax.swing.JMenu btnViewVIP;
    private javax.swing.JTextField createDate;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField10;
    private javax.swing.JTextField jTextField12;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTable orderDetailTable;
    private javax.swing.JTextField orderStatus;
    private com.ordering.pojo.TOrderHead tOrderHead1;
    private javax.swing.JTextField updateTime;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}
